package cnooc.autoControl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cnooc.common.annotation.Log;
import cnooc.common.core.controller.BaseController;
import cnooc.common.core.domain.AjaxResult;
import cnooc.common.enums.BusinessType;
import cnooc.autoControl.domain.AutoControlStrategy;
import cnooc.autoControl.service.IAutoControlStrategyService;
import cnooc.common.utils.poi.ExcelUtil;
import cnooc.common.core.page.TableDataInfo;

/**
 * 自动控制策略Controller
 * 
 * @author chen
 * @date 2025-07-19
 */
@RestController
@RequestMapping("/autoControl/strategy")
public class AutoControlStrategyController extends BaseController
{
    @Autowired
    private IAutoControlStrategyService autoControlStrategyService;

    /**
     * 查询自动控制策略列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AutoControlStrategy autoControlStrategy)
    {
        startPage();
        List<AutoControlStrategy> list = autoControlStrategyService.selectAutoControlStrategyList(autoControlStrategy);
        return getDataTable(list);
    }

    /**
     * 导出自动控制策略列表
     */
    @Log(title = "自动控制策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AutoControlStrategy autoControlStrategy)
    {
        List<AutoControlStrategy> list = autoControlStrategyService.selectAutoControlStrategyList(autoControlStrategy);
        ExcelUtil<AutoControlStrategy> util = new ExcelUtil<AutoControlStrategy>(AutoControlStrategy.class);
        util.exportExcel(response, list, "自动控制策略数据");
    }

    /**
     * 获取自动控制策略详细信息
     */
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return success(autoControlStrategyService.selectAutoControlStrategyByJobId(jobId));
    }

    /**
     * 新增自动控制策略
     */
    @Log(title = "自动控制策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AutoControlStrategy autoControlStrategy)
    {
        return toAjax(autoControlStrategyService.insertAutoControlStrategy(autoControlStrategy));
    }

    /**
     * 修改自动控制策略
     */
    @Log(title = "自动控制策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AutoControlStrategy autoControlStrategy)
    {
        return toAjax(autoControlStrategyService.updateAutoControlStrategy(autoControlStrategy));
    }

    /**
     * 删除自动控制策略
     */
    @Log(title = "自动控制策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(autoControlStrategyService.deleteAutoControlStrategyByIds(ids));
    }

    /**
     * 删除自动控制策略
     */
    @Log(title = "自动控制策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/delStrategyByJobId/{jobId}")
    public AjaxResult removeByJobId(@PathVariable Long[] jobId)
    {
        return toAjax(autoControlStrategyService.deleteAutoControlStrategyByJobId(jobId));
    }
}
